<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>コントロールパネル</title>
    
    <link href="./assets/styles/default.css" rel="stylesheet" />
    <script src="./assets/scripts/libs/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script src="./assets/scripts/plugins/jquery.tagsinput.min.js" type="text/javascript"></script>
    <script src="./assets/scripts/import.js" type="text/javascript"></script>
    <script>
		$(function(){
			back_to_search();
			getRole($('select[name=site_id] option').first().val());
			
			$('#plugins .left a').click(function(){
			//	$('#codearea').append("<textarea name=''></textarea>");
				$('.labels input[type=checkbox]').each(function(){
					if(!$(this).attr('checked')){
						$(this).closest("label").click();
					}
				});
			});
			
			$('#plugins .right a').click(function(){
				$('.labels input[type=checkbox]').each(function(){
					if($(this).attr('checked')){
						$(this).closest("label").click();
					}
				});
			});
			
		});
		
		function getRole(site_id){
			$.ajax({
				url      : "./staff.php?op=get_auth&mode=plugin&site_id=" + site_id,
				dataType : "json",
				async    : false,
				success  : function( data ){
					var html = '';
					$.each(data, function(){
						html += '<label><input type="checkbox" name="forms_auth[auth][]" value="' + this.value + '"><img src="./assets/images/icons/sidemenu/' + this.name.toLowerCase().split(' ')[0] + '.png" />' + this.name + '</label>';
					});
					$(".authList div").html(html);
					setRadioAndCheckbox();
				},
				error : function(){
				}
			});
		}
    </script>
    
</head>
<body>

{include file='include/header.inc.html'}

<div id="container">
	<aside id="accordion">
    	<div id="aside_inner">
    		{include file='include/menu.inc.html'}
        </div>
    </aside>
    
    <article>
    	<h2><span>&nbsp;</span>Staff<p><a href="javascript:;">Open Plugins</a></p></h2>
        <nav>
            <ul>
            <li><a href="staff.php"><span>スタッフ検索</span></a></li>
            <li><a href="staff.php?op=regist"><span>スタッフ登録</span></a></li>
            <li {if !$phase}class="active"{/if}><a href="{$smarty.server.SCRIPT_NAME}"><span>ロール検索</span></a></li>
            <li {if $phase == 'input'}class="active"{/if}><a href="{$smarty.server.SCRIPT_NAME}?op=regist"><span>ロール登録</span></a></li>
            </ul>
        </nav>
        
        <section id="content">
        
        	<h3>ロール{if $forms.id ==''}登録{else}更新{/if}</h3>
{if $phase == 'input'}
                        <p class="message">内容を確認し、{if $forms.id == ''}登録{else}更新{/if}ボタンをクリックしてください。</p>
                        <form name="fm" action="{$smarty.server.SCRIPT_NAME}" method="post">
                    
                    	<ul class="t_btns">
                            {if $forms.id != ''}
                                <li class="left delete"><button type="button" class="chk_delete"><em>&nbsp;</em>削除</button></li>
                                <li class="right refresh"><button type="button" class="chk_update"><em>&nbsp;</em>更新</button></li>
                            {else}
                                <li class="single add"><button type="button" class="chk_add"　{if $site_list|@count == 0}disabled="disabled"{/if}><em>&nbsp;</em>登録</button></li>
                            {/if}
                        </ul>
                    
                        <h4><span>&nbsp;</span>基本情報</h4>

                            <table class="formTable">
                                    <tbody>
{if $forms.id != ''}
                                            <tr>
                                                    <th>登録日時</th>
                                                    <td>
                                                            {$forms.r_date}<input type="hidden" name="forms[r_date]" value="{$forms.r_date}" />
                                                    </td>
                                            </tr>
                                            <tr>
                                                    <th>更新日時</th>
                                                    <td>
                                                            {$forms.u_date}<input type="hidden" name="forms[u_date]" value="{$forms.u_date}" />
                                                    </td>
                                            </tr>
                                            <tr>
                                                    <th>ID</th>
                                                    <td>
                                                            {"%05d"|sprintf:$forms.id}
                                                    </td>
                                            </tr>
                                            <tr>
                                                    <th>サイト</th>
                                                    <td>
                                                            {$site_list[$forms.site_id]|escape}
                                                            <input type="hidden" name="forms[site_id]" value="{$forms.site_id|escape}"/>
                                                    </td>
                                            </tr>

{else}
                                            <tr>
                                                    <th class="must">サイト</th>
                                                    <td>
                                                            {if $site_list|@count == 0}
                                                                    サイトが登録されていません
                                                            {else}
                                                                    <select name="forms[site_id]" onChange="getRole(this.value);">
                                                                        <option value="">選択してください</option>
                                                                        {html_options options=$site_list selected=$forms.site_id}
                                                                    </selcet>
                                                            {/if}
                                                            {$err.site_id nofilter}
                                                    </td>
                                            </tr>
{/if}
                                            <tr>
                                                    <th class="must">ロール名</th>
                                                    <td>
                                                            <input type="text" name="forms[name]" class="text" value="{$forms.name|escape}" />{$err.name nofilter}
                                                    </td>
                                            </tr>
                                            <tr>
                                                    <th class="must">状態</th>
                                                    <td>
                                                            <label><input type="radio" name="forms[actived]" value="1"{if $forms.actived == 1} checked{/if} />利用中</label>　
                                                            <label><input type="radio" name="forms[actived]" value="0"{if $forms.actived != 1} checked{/if} />停止</label>
                                                            {$err.actived nofilter}
                                                    </td>
                                            </tr>
                                            
                                            
                                            <tr>
                                                <th>権限</th>
                                                {if $forms.id == ''}
                                                    <td class="authList labels">
                                                        <ul id="plugins" class="btns b10">
                                                            <li class="btn left c"><a href="javascript:;">全てチェック</a></li>
                                                            <li class="btn right c"><a href="javascript:;">全て外す</a></li>
                                                        </ul>
                                                        <div></div>
                                                    </td>
                                                {else}
                                                    <td class="authList labels">
                                                        <ul id="plugins" class="btns b10">
                                                            <li class="btn left c"><a href="javascript:;">全てチェック</a></li>
                                                            <li class="btn right c"><a href="javascript:;">全て外す</a></li>
                                                        </ul>
                                                        {foreach from=$plugin item=one}
                                                            <label><input type="checkbox" name="forms_auth[auth][]" value="{$one.value}" {if $one.checked}checked{/if}><img src="./assets/images/icons/sidemenu/{$one.img_file_name}.png" />{$one.name}</label>
                                                        {/foreach}
                                                    </td>
                                                {/if}
                                            </tr>
                                    </tbody>
                            </table>

                            <p class="button">
{if $forms.id == ''}
                                <button type="button" class="submit btn_submit" id="btn_regist" {if $site_list|@count == 0}disabled="disabled"{/if}><span>登録</span></button>
{else}
                                <button type="button" class="submit" id="btn_delete"><span>削除</span></button>
                                <button type="button" class="submit btn_submit" id="btn_update"><span>更新</span></button>
{/if}
                            </p>
                            <input type="hidden" name="id" value="{$forms.id|escape}" />
                            <input type="hidden" name="do" value="{if !isset($forms.id) || $forms.id == ''}validate_regist_form{else}validate_update_form{/if}"/>
                            <input type="hidden" name="mode" value="input" />
                            <input type="hidden" name="confirm_key" value="{$confirm_key|escape}"/>
                    </form>
{/if}

{if $phase == 'complete'}
                    <p class="message">{$message}</p>
                    <ul class="result_btn">
                            <li><a href="staff_role.php">一覧に戻る</a></li>
                            <li><a href="staff_role.php?op=regist">続けて新規登録する</a></li>
                        {if $forms.id != ''}
                            <li><a href="{$smarty.server.SCRIPT_NAME}?op=edit&id={$forms.id|escape}">登録した内容を更新する</a></li>
                        {/if}
                    </ul>
{/if}

        </section>
    </article>
    
</div>

{include file='include/footer.inc.html'}

</body>
</html>